package wxdb.ui;



import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

public class ModifyRecord extends JDialog{
	
	private JButton insButton = new JButton("Insert");
	private JButton delButton = new JButton("Delete");
	private JButton updButton = new JButton("Update");

	private JSeparator sep1 = new JSeparator();
	private JSeparator sep2 = new JSeparator();
	private JSeparator sep3 = new JSeparator();
	
	private JLabel insLabel = new JLabel("Insert :");
	private JLabel delLabel = new JLabel("Delete :");
	private JLabel updLabel = new JLabel("Update :");
	private JLabel dbLabel = new JLabel("Input Database Name :");
	private JLabel tbLabel = new JLabel("Input Tabel Name :");
	private JLabel rid1 = new JLabel("KEY: ");
	private JLabel rid2 = new JLabel("KEY: ");

	private JTextField databaseName = new JTextField(10);
	private JTextField tableName = new JTextField(10);
	private JTextArea insInput = new JTextArea(3,30);
	private JTextField delRid = new JTextField(5);
	private JTextArea updInput = new JTextArea(3,30);
	private JTextField updRid = new JTextField(5);
	
	private JPanel pane = new JPanel();
	
	Font fon = new Font("Dialog",Font.PLAIN,15);
	
	
	void buildConstraints(GridBagConstraints gbc,int gx, int gy, int gw, int gh, int wx, int wy){
		gbc.gridx = gx;			
		gbc.gridy = gy;			
		gbc.gridwidth = gw;		
		gbc.gridheight = gh;	
		gbc.weightx = wx;		
		gbc.weighty = wy;		
	}
	
	
	private void setMyPane(){
		GridBagLayout gridbag = new GridBagLayout();
		GridBagConstraints constraints = new GridBagConstraints();
		pane.setLayout(gridbag);
		
/*

 */
		constraints=new GridBagConstraints();
		constraints.anchor=GridBagConstraints.CENTER;
		constraints.insets=new Insets(5,5,5,5);
		gridbag.setConstraints(dbLabel, constraints);
		pane.add(dbLabel);
		
		constraints=new GridBagConstraints();
		constraints.insets=new Insets(5,5,5,5);
		constraints.fill=GridBagConstraints.HORIZONTAL;
		constraints.gridwidth=GridBagConstraints.REMAINDER;
		gridbag.setConstraints(databaseName, constraints);
		pane.add(databaseName);
/*
 *	
 */
		constraints=new GridBagConstraints();
		constraints.insets=new Insets(5,5,5,5);
		constraints.anchor=GridBagConstraints.CENTER;
		gridbag.setConstraints(tbLabel, constraints);
		pane.add(tbLabel);
		
		constraints=new GridBagConstraints();
		constraints.insets=new Insets(5,5,5,5);
		constraints.fill=GridBagConstraints.HORIZONTAL;
		constraints.gridwidth=GridBagConstraints.REMAINDER;
		gridbag.setConstraints(tableName, constraints);
		pane.add(tableName);
/**/		
//		  JSeparator separator=new JSeparator();
		constraints=new GridBagConstraints();
		
		constraints.fill=GridBagConstraints.HORIZONTAL;
		constraints.gridwidth=GridBagConstraints.REMAINDER;
		gridbag.setConstraints(sep1,constraints);
		pane.add(sep1);
		  
//		  constraints=new GridBagConstraints();
//		  constraints.anchor=GridBagConstraints.EAST;
//		  buildConstraints(constraints,0,3,1,1,1,1);
//		buildConstraints(constraints,0,2,1,1,1,1);
	//	gridbag.setConstraints(sep1, constraints);
//		pane.add(sep1);

		constraints=new GridBagConstraints();
		constraints.insets=new Insets(5,5,5,5);
		constraints.fill=GridBagConstraints.HORIZONTAL;
		constraints.gridwidth=GridBagConstraints.REMAINDER;
		gridbag.setConstraints(insLabel, constraints);
		pane.add(insLabel);
				
		constraints=new GridBagConstraints();
		constraints.fill=GridBagConstraints.BOTH;
		constraints.gridwidth=GridBagConstraints.REMAINDER;
		constraints.insets=new Insets(5,5,5,5);
		gridbag.setConstraints(insInput, constraints);
		pane.add(insInput);
		
		constraints=new GridBagConstraints();
//		constraints.fill=GridBagConstraints.HORIZONTAL;
		constraints.insets=new Insets(5,5,5,5);
		constraints.gridwidth=GridBagConstraints.REMAINDER;
		gridbag.setConstraints(insButton, constraints);
		pane.add(insButton);
			
		
		constraints=new GridBagConstraints();

		constraints.fill=GridBagConstraints.HORIZONTAL;
		constraints.gridwidth=GridBagConstraints.REMAINDER;
		gridbag.setConstraints(sep2, constraints);
		pane.add(sep2);
		
		constraints=new GridBagConstraints();
		constraints.insets=new Insets(5,5,5,5);
		constraints.fill=GridBagConstraints.HORIZONTAL;
		constraints.gridwidth=GridBagConstraints.REMAINDER;
		gridbag.setConstraints(delLabel, constraints);
		pane.add(delLabel);
		
		constraints=new GridBagConstraints();
		constraints.insets=new Insets(5,5,5,5);
		constraints.fill=GridBagConstraints.CENTER;
		gridbag.setConstraints(rid1, constraints);
		pane.add(rid1);
		
		constraints=new GridBagConstraints();
		constraints.insets=new Insets(5,5,5,5);
		constraints.fill=GridBagConstraints.HORIZONTAL;
		constraints.gridwidth=GridBagConstraints.REMAINDER;
		gridbag.setConstraints(delRid, constraints);
		pane.add(delRid);
	
		constraints=new GridBagConstraints();
		constraints.insets=new Insets(5,5,5,5);
		constraints.fill=GridBagConstraints.CENTER;
		constraints.gridwidth=GridBagConstraints.REMAINDER;
		gridbag.setConstraints(delButton, constraints);
		pane.add(delButton);
		
		constraints=new GridBagConstraints();
		constraints.insets=new Insets(5,5,5,5);
		constraints.fill=GridBagConstraints.HORIZONTAL;
		constraints.gridwidth=GridBagConstraints.REMAINDER;
		gridbag.setConstraints(sep3, constraints);
		pane.add(sep3);
		
		constraints=new GridBagConstraints();
		constraints.insets=new Insets(5,5,5,5);
		constraints.fill=GridBagConstraints.HORIZONTAL;
		constraints.gridwidth=GridBagConstraints.REMAINDER;
		gridbag.setConstraints(updLabel, constraints);
		pane.add(updLabel);
		
		constraints=new GridBagConstraints();
		constraints.insets=new Insets(5,5,5,5);
		constraints.fill=GridBagConstraints.CENTER;
		gridbag.setConstraints(rid2, constraints);
		pane.add(rid2);
		
		constraints=new GridBagConstraints();
		constraints.insets=new Insets(5,5,5,5);
		constraints.fill=GridBagConstraints.HORIZONTAL;
		constraints.gridwidth=GridBagConstraints.REMAINDER;
		gridbag.setConstraints(updRid, constraints);
		pane.add(updRid);
		
		constraints=new GridBagConstraints();
		constraints.insets=new Insets(5,5,5,5);
		constraints.fill=GridBagConstraints.BOTH;
		constraints.gridwidth=GridBagConstraints.REMAINDER;
		gridbag.setConstraints(updInput, constraints);
		pane.add(updInput);
		
		constraints=new GridBagConstraints();
		constraints.insets=new Insets(5,5,5,5);
		constraints.fill=GridBagConstraints.CENTER;
		constraints.gridwidth=GridBagConstraints.REMAINDER;
		gridbag.setConstraints(updButton, constraints);	
		pane.add(updButton);
		
		setLocation(200,80);
		setContentPane(pane);
	}
	

	private void initListener(){
		ActListener actListener = new ActListener();
		insButton.addActionListener(actListener);
		updButton.addActionListener(actListener);
		delButton.addActionListener(actListener);
	}
	
	class ActListener implements ActionListener{
		public void actionPerformed(ActionEvent e){
			if(e.getSource() == insButton)
				insButtonRun();
			if(e.getSource() == updButton)
				updButtonRun();
			if(e.getSource() == delButton)
				delButtonRun();
		}
	}
	
	private void delButtonRun(){
		System.out.println("delButtonRun");
	}
	
	private void updButtonRun(){
		System.out.println("updButtonRun");
	}
	
	private void insButtonRun(){
		System.out.println("insButtonRun");
	}
	
	public ModifyRecord(){
		setTitle("Modify Record");
		setSize(400,550);
		initListener();
		setMyPane();
		setVisible(true);
		setResizable(false);
	}
}
